<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>examle3</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
  <h1>examle3</h1>
  <hr>
  <div id="app">
    {{num}}
    <p><button @click="add">add</button></p>
  </div>
  <button onclick="reduce()">reduce</button>
  <p><button onclick="reduceOnce()">reduceOnce</button></p>
  <p><button onclick="off()">off</button></p>
  <script type="text/javascript">
  var app = new Vue({
    el:'#app',
    data:{
      num:1
    },
    methods:{
      add:function(){
        this.num++;
      }
    }
  })
  app.$on('reduce',function(){
    console.log('执行了reduce方法');
    this.num--;
  })
  app.$once('reduceOnce',function(){
    console.log('只执行了一次方法');
    this.num--;
  })
  function reduce(){
    app.$emit('reduce');
  }
  function reduceOnce(){
    app.$emit('reduceOnce');
  }
  function off(){
    app.$off('reduce');
  }
  </script>
</body>
</html>